//
//  favorite.m
//  IMGII
//
//  Created by 步遴 李 on 12-4-11.
//  Copyright (c) 2012年 __MyCompanyName__. All rights reserved.
//

#import "favoriteViewController.h"


#import "AppDelegate.h"
#import "RegexKitLite.h"

@implementation favoriteViewController
@synthesize testButton,readButton;


/*-(IBAction)readPosts:(id)sender
{
    NSError *error;
    blogs = [context executeFetchRequest:cdrequest error:&error];
    if (blogs == nil) {
        NSLog(@"error because of %@",[error localizedDescription]);
    }
    blog= [blogs objectAtIndex:12];
    NSLog(@"%d",[blogs count]);   
    NSLog(@"%@",blog.title);
}
*/
-(IBAction)refreshPosts:(id)sender
{


    
}


- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        
    }
    return self;
}

- (void)didReceiveMemoryWarning
{
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
    
    // Release any cached data, images, etc that aren't in use.
}

#pragma mark - View lifecycle

- (void)viewDidLoad
{
    
       
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
}

- (void)viewDidUnload
{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
-(NSString *)addUrl:(NSString *)context {
    NSString *link = context;
    //NSString *temp = [[NSString alloc]init];
    NSString *regexString = @"<img[^>]+alt=\"([^>]+)\"[^>]*>";
    NSArray *splitArray = [context componentsMatchedByRegex:regexString];
    for (NSInteger i = 0; i < [splitArray count]; i++) {
        regexString  = @"\\bhttps?://[a-zA-Z0-9\\-.]+(?::(\\d+))?(?:(?:/[a-zA-Z0-9\\-._?,'+\\&%$=~*!():@\\\\]*)+)?";
        NSArray *tempArry = [[splitArray objectAtIndex:i] componentsMatchedByRegex:regexString];
        NSString *temp = [[NSString alloc]initWithFormat:@"<a href=\"pic:%@\">%@</a>",[tempArry objectAtIndex:0],[splitArray objectAtIndex:i]]; 
        link = [link stringByReplacingOccurrencesOfString:[splitArray objectAtIndex:i] withString:temp];
        [temp release];
    } 

    return link;
}

- (NSString *)getThumbnail:(NSString *)context{
    NSString *regexString  = @"\\bhttps?://[a-zA-Z0-9\\-.]+(?::(\\d+))?(?:(?:/[a-zA-Z0-9\\-._?,'+\\&%$=~*!():@\\\\]*)+)?";
    NSArray *splitArray = [context componentsMatchedByRegex:regexString];
    NSString *link = [splitArray objectAtIndex:0];
    link = [link stringByReplacingOccurrencesOfString:@".jpg" withString:@"-160x160.jpg"];
    link = [link stringByReplacingOccurrencesOfString:@".jpeg" withString:@"-160x160.jpeg"];
    return link;
    link = [link stringByReplacingOccurrencesOfString:@".gif" withString:@"-160x160.gif"];
}

@end
